package com.ihr360.payroll.model.meta;

import com.ihr360.commons.entity.metadata.IEntityMeta;
import com.ihr360.commons.model.meta.AbstractPropertyMeta;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;

/**
 * 属性元信息
 */
@Entity
public class EntityMeta extends AbstractPropertyMeta implements IEntityMeta<Long, PropertyMeta> {
    private static final long serialVersionUID = 3388512701618090064L;

    /**
     * 类型
     */
    @Column(nullable = false, length = 100)
    private Class<?> type;

    /**
     * 编码
     */
    @Column(nullable = false, length = 32, unique = true)
    //TODO
    //@CodeGenerator(length = 8)
    private String code;

    /**
     * 名称
     */
    @Column(nullable = false, length = 50)
    private String name;

    /**
     * 英文名
     */
    @Column(length = 100)
    private String engName;

    /**
     * 属性元信息列表
     */
    @OneToMany(mappedBy = "entityMeta", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<PropertyMeta> propMetas = new ArrayList<>();

    /**
     * 是否支持自定义字段
     */
    private boolean extendable = false;

    /**
     * 数据源
     */
    @Column(length = 200)
    private String provider;

    @Column(length = 500)
    private String hql;

    public Class<?> getType() {
        return type;
    }

    public void setType(Class<?> type) {
        this.type = type;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEngName() {
        return engName;
    }

    public void setEngName(String engName) {
        this.engName = engName;
    }

    public List<PropertyMeta> getPropMetas() {
        return propMetas;
    }

    public void setPropMetas(List<PropertyMeta> propMetas) {
        this.propMetas = propMetas;
    }

    public String getProvider() {
        return provider;
    }

    public void setProvider(String provider) {
        this.provider = provider;
    }

    public String getHql() {
        return hql;
    }

    public void setHql(String hql) {
        this.hql = hql;
    }

    public boolean isExtendable() {
        return extendable;
    }

    public void setExtendable(boolean extendable) {
        this.extendable = extendable;
    }
}